﻿BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
CREATE TABLE dbo.Tmp_WikiEntry
	(
	WikiEntryID int NOT NULL IDENTITY (1, 1),
	InstanceID nvarchar(50) NOT NULL,
	PageID nvarchar(100) COLLATE Latin1_General_CI_AS NOT NULL,
	Version int NOT NULL,
	AuthorName nvarchar(256) COLLATE Latin1_General_CI_AS NOT NULL,
	Text nvarchar(MAX) COLLATE Latin1_General_CI_AS NOT NULL,
	TimeCreated smalldatetime NOT NULL
	)  ON [PRIMARY]
	 TEXTIMAGE_ON [PRIMARY]
GO
SET IDENTITY_INSERT dbo.Tmp_WikiEntry ON
GO
IF EXISTS(SELECT * FROM dbo.WikiEntry)
	 EXEC('INSERT INTO dbo.Tmp_WikiEntry (WikiEntryID, InstanceID, PageID, Version, AuthorName, Text, TimeCreated)
		SELECT WikiEntryID, InstanceID, CONVERT(nvarchar(100), PageID), Version, AuthorName, CONVERT(nvarchar(MAX), Text), TimeCreated FROM dbo.WikiEntry WITH (HOLDLOCK TABLOCKX)')
GO
SET IDENTITY_INSERT dbo.Tmp_WikiEntry OFF
GO
DROP TABLE dbo.WikiEntry
GO
EXECUTE sp_rename N'dbo.Tmp_WikiEntry', N'WikiEntry', 'OBJECT' 
GO
ALTER TABLE dbo.WikiEntry ADD CONSTRAINT
	PK_WikiEntryID PRIMARY KEY CLUSTERED 
	(
	WikiEntryID
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

GO
CREATE UNIQUE NONCLUSTERED INDEX IX_WikiEntry ON dbo.WikiEntry
	(
	InstanceID,
	PageID,
	Version
	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
COMMIT
